package gov.pbc.nn.kjgl.software.dao;

import gov.pbc.nn.core.bdf.entity.Dept;
import gov.pbc.nn.core.dao.AbstractJdbcDao;
import gov.pbc.nn.core.utils.EntityRowMapperUtils;
import gov.pbc.nn.core.utils.SecurityUtils;
import gov.pbc.nn.kjgl.entity.Project;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.bstek.bdf2.core.CoreJdbcDao;
import com.bstek.bdf2.core.business.IDept;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.orm.ParseResult;
import com.bstek.bdf2.core.service.IDeptService;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

@Repository
public class ProjectMangeJdbcCoreDao extends  CoreJdbcDao {

	/**
	 * 使用jdbc對用戶名進行查詢
	 * 
	 * @return
	 */
	// public List<Map<String, Object>> getAll() {
	// List<Map<String, Object>> lists = null;
	// // if (username != null) {
	// // String sql =
	// //
	// "select u.USERNAME_,u.CNAME_ ,d.NAME_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  where  u.CNAME_ like concat(?,'%') or d.NAME_ like concat('%',?,'%') ";
	// // lists = this.getJdbcTemplate().queryForList(sql, new String[] {
	// // username, username });
	// //
	// // } else {
	// String sql1 =
	// "select u.MOBILE_,u.USERNAME_,u.CNAME_ ,d.NAME_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  ";
	// lists = this.getJdbcTemplate("pbcnn.core.dataSource").queryForList(sql1);
	// // }
	// return lists;
	// }

	public List<Map<String, Object>> getAll(Page<Map<String, Object>> page, String username) {
		List<Map<String, Object>> lists = null;
		if (username != null) {
			String sql = "select u.MOBILE_,u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  where  u.CNAME_ like concat(?,'%') or d.NAME_ like concat('%',?,'%') ";
			this.pagingQuery(page, sql, new Object[] { username, username });
		} else {
			String sql1 = "select u.MOBILE_,u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  ";
			this.pagingQuery(page, sql1);
		}
		return lists;
	}
	
}
